package cn.wit.test;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;

import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class DemoGetFilePath extends HttpServlet{
	
	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		
		ServletContext context = getServletContext();
		
		//获取项目得部署路径
		String filePath = context.getRealPath("/");
		
		System.out.println(filePath);
		
		String filedb = context.getRealPath("/WEB-INF/classes/resource/db.config");
		System.out.println(filedb);
	
		File file = new File(filedb);
		
		System.out.println("文件是不是存在："+file.exists());
		
		BufferedReader br = new BufferedReader(new FileReader(file));
		System.out.println(br.readLine());
		
		br.close();
		
		String file2text = context.getRealPath("/1.text");
		
		File file1 = new File(file2text);
		
		br = new BufferedReader(new FileReader(file1));
		System.out.println(br.readLine());
		
		
	}

}
